package Chapter6;

import java.util.Vector;

//122页例6.6
class Person2 {
    public String name;

    public String getName() {
        return name;
    }

    public void setName(String n) {
        name = n;
    }
}

class Employee2 extends Person2 {
    public int Employee2Number;

    public int getEmployee2Number() {
        return Employee2Number;
    }
}

class Manager2 extends Employee2 {
    public String department;
    public Vector<String> responsibilities;

    public Vector<String> getResponsibilities() {
        return responsibilities;
    }
}

public class ObjectTransformation {
    public static void main(String[] args) {
//        Employee2 jim = new Employee2();
//        jim.name = "jim";
//        jim.Employee2Number = 1001;
//        System.out.println(jim.getName());
//        Manager2 betty = new Manager2();
//        betty.Employee2Number = 2001;
//        betty.responsibilities = new Vector<String>();
//        betty.responsibilities.add("Internet project");
//        System.out.println(betty.getName());
//        System.out.println(betty.getEmployee2Number());
        Employee2 betty = new Manager2(); //此时为向上转型
        betty.name = "Betty";
        System.out.println(betty.getName());
        betty.Employee2Number = 2001;
        if (betty instanceof Manager2) { //如果父类的引用变量betty是子类对象
            Manager2 m = (Manager2) betty; //进行强制转换 从向上转型的基础上向下转型
            m.department = "Test";
            System.out.println("访问Manager2的特有属性：" + m.department);
        }

    }
}
